origin = 0

# 闭包避免了普通函数中到处使用全局变量，容易污染全局变量，闭包让函数具备了自封闭的特性


def factory(pos):
    def go(step):
        nonlocal pos
        new_pos = pos + step
        pos = new_pos
        return new_pos

    return go


f = factory(origin)
print(f(2))
print(f(3))
print(f(6))
